#ifndef BUTTONSTYLES_H
#define BUTTONSTYLES_H

#include <QPushButton>
#include <QToolButton>
#include <QGraphicsDropShadowEffect>
#include <QComboBox>
#include <QGroupBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QScrollArea>
namespace ButtonStyles {

// 主按钮（蓝色圆角）
inline void applyPrimary(QPushButton* btn) {
    btn->setCursor(Qt::PointingHandCursor);
    btn->setStyleSheet(R"(
        QPushButton {
            background-color: #3B82F6;
            color: white;
            border: none;
            border-radius: 10px;
            padding: 8px 16px;
            font-weight: 600;
        }
        QPushButton:hover { background-color: #2563EB; }
        QPushButton:pressed { background-color: #1D4ED8; }
        QPushButton:disabled { background-color: #93C5FD; color: #E5E7EB; }
    )");
}

// 次级按钮（幽灵按钮）
inline void applySecondary(QPushButton* btn) {
    btn->setFlat(true);
    btn->setCursor(Qt::PointingHandCursor);
    btn->setStyleSheet(R"(
        QPushButton {
            background: transparent;
            color: #374151;
            border: 2px solid #D1D5DB;
            border-radius: 10px;
            padding: 7px 15px;
        }
        QPushButton:hover { border-color: #9CA3AF; background-color: #F3F4F6; }
        QPushButton:pressed { background-color: #E5E7EB; }
        QPushButton:disabled { color: #9CA3AF; border-color: #E5E7EB; }
    )");
}

// 渐变按钮
inline void applyGradient(QPushButton* btn) {
    btn->setCursor(Qt::PointingHandCursor);
    btn->setStyleSheet(R"(
        QPushButton {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                        stop:0 #06B6D4, stop:1 #22C55E);
            color: white;
            border: none;
            border-radius: 12px;
            padding: 10px 18px;
            font-weight: 600;
        }
        QPushButton:hover {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                        stop:0 #08C1E2, stop:1 #2DD06D);
        }
        QPushButton:pressed {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                        stop:0 #05A9C2, stop:1 #1FB457);
        }
        QPushButton:disabled { background: #A7F3D0; color: #F0FDF4; }
    )");
}

// 给按钮加阴影（可选叠加）
inline void addShadow(QWidget* w) {
    auto *fx = new QGraphicsDropShadowEffect(w);
    fx->setBlurRadius(16);
    fx->setOffset(0, 4);
    fx->setColor(QColor(0,0,0,60));
    w->setGraphicsEffect(fx);
}
// =========================
// 下拉框（左侧面板推荐：描边风格）
// =========================
// ========== 无自定义箭头：Outlined 风格 ==========
inline void applyComboOutlined(QComboBox* cb) {
    cb->setStyleSheet(R"(
        QComboBox {
            background: transparent;
            color: #374151;
            border: 2px solid #D1D5DB;
            border-radius: 10px;
            padding: 7px 15px;
        }
        QComboBox:hover { border-color: #9CA3AF; background-color: #F3F4F6; }
        QComboBox:pressed { background-color: #E5E7EB; }
        QComboBox:disabled { color: #9CA3AF; border-color: #E5E7EB; }
    )");
}

//滚东区域
inline void applyScroll(QScrollArea* gd) {
    gd->setStyleSheet(R"(
        QScrollArea {
            background: #F9FAFB;
            border: 1px solid #E5E7EB;
            border-radius: 10px;
            margin-top: 10px;
            padding: 8px 10px 10px 10px;
        }
        QScrollArea::title {
            subcontrol-origin: margin;
            subcontrol-position: top left;
            padding: 0 6px;
            color: #374151;
            font-weight: 500;
        }
    )");
}
// 标题更弱化（适合“设备信息”的小分段）
inline void applyGroupSubtle(QGroupBox* gb) {
    gb->setStyleSheet(R"(
        QGroupBox {
            background: #F9FAFB;
            border: 1px solid #E5E7EB;
            border-radius: 10px;
            margin-top: 10px;
            padding: 8px 10px 10px 10px;
        }
        QGroupBox::title {
            subcontrol-origin: margin;
            subcontrol-position: top left;
            padding: 0 6px;
            color: #374151;
            font-weight: 500;
        }
    )");
}

// =========================
// SpinBox（显示时长等数值输入）
// =========================
inline void applySpinBox(QSpinBox* sp) {
    // 确保没被代码关闭按钮
    sp->setButtonSymbols(QAbstractSpinBox::UpDownArrows);

    sp->setStyleSheet(R"(
        QSpinBox {
            background: transparent;
            color: #374151;
            border: 2px solid #D1D5DB;
            border-radius: 10px;
            padding: 7px 15px;
        }
        QSpinBox:hover { border-color: #9CA3AF; background-color: #F3F4F6; }
        QSpinBox:pressed { background-color: #E5E7EB; }
        QSpinBox:disabled { color: #9CA3AF; border-color: #E5E7EB; }
    )");
}



// =========================
// CheckBox（“暂停显示/隐藏统计/总开关”等）
// =========================
inline void applyCheckBox(QCheckBox* cb) {
    cb->setStyleSheet(R"(
        QCheckBox {
            background: transparent;
            color: #374151;
            border: 2px solid #D1D5DB;
            border-radius: 10px;
            padding: 7px 15px;
        }
        QCheckBox:hover { border-color: #9CA3AF; background-color: #F3F4F6; }
        QCheckBox:pressed { background-color: #E5E7EB; }
        QCheckBox:disabled { color: #9CA3AF; border-color: #E5E7EB; }
    )");
}

// =========================
// ToolButton（左侧“设备按钮/更多菜单”）
// =========================
inline void applyToolButton(QToolButton* tb) {
    tb->setCursor(Qt::PointingHandCursor);
    tb->setStyleSheet(R"(
        QToolButton {
            background: #10B981;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 6px 10px;
        }
        QToolButton:hover { background: #059669; }
        QToolButton:pressed { background: #047857; }
        QToolButton::menu-indicator { image: none; } /* 去小三角，如需保留删除此行 */
    )");
}

} // namespace ButtonStyles

#endif // BUTTONSTYLES_H
